@extends('admin.layout.app')
@section('title', '权限管理')

@section('nav')
    @include('admin.layout.nav', ['title'=> ['系统管理','权限管理']])
@endsection

@section('content')
    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title">权限管理</h3>
        </div>
        <!-- /.box-header -->
        <div class="box-body">
            <form class="form-inline" method="get" action="" style="margin-bottom: 15px;">
                <div class="form-group">
                    <label for="title">权限名：</label>
                    <input type="text" class="form-control" name="username" placeholder="请输入">
                </div>
                <button type="submit" class="btn btn-default">查询</button>
                <a class="btn btn-primary" href="/permissions/add">添加</a>
            </form>
            <table class="table table-bordered table-hover">
                <thead>
                <tr class="active">
                    <th style="width: 80px">id</th>
                    <th>权限名</th>
                    <th>显示名</th>
                    <th>描述</th>
                    <th>创建时间</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @forelse ($permissions as $permission)
                    <tr>
                        <td>{{$permission->id}}</td>
                        <td>{{$permission->name}}</td>
                        <td>{{$permission->display_name}}</td>
                        <td>{{$permission->description}}</td>
                        <td>{{$permission->created_at}}</td>
                        <td>{{$permission->updated_at}}</td>
                        <td>
                            <a class="btn btn-sm btn-info" href="/admin/users/update?id={{$permission->id}}">更改</a>
                            <button class="btn btn-sm btn-danger deleteitem" data-id="{{$permission->id}}">删除</button>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="7" align="center">暂无数据</td>
                    </tr>
                @endforelse
                </tbody>
            </table>
        </div>
        <!-- /.box-body -->
        <div class="box-footer clearfix">
            {{ $permissions->links() }}
        </div>
    </div>
@endsection

@section('style')
    <style>

    </style>
@endsection

@section('js')
    <script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
    <script >

        $(function () {
            $('.deleteitem').click(function () {
                var id_ = $(this).attr('data-id');
                var confirm_index = layer.confirm("您确定要删除该权限吗？",{}, function () {
                    layer.close(confirm_index);
                    var load_index = layer.msg('正在处理中', {
                        icon: 16,
                        shade: 0.5,
                        time: 15000
                    });
                    $.ajaxSetup({
                        headers: {
                            'X-CSRF-TOKEN': "{{ csrf_token() }}"
                        }
                    });
                    $.post('/permissions/delete', {id: id_}, function (res) {
                        if(res.code == 200){
                            layer.close(load_index);
                            layer.msg('操作成功！', {icon: 1});
                            window.location.reload();
                        }else{
                            layer.alert(res.message, {icon: 5});
                        }
                    });
                });
            });
        })
    </script>
@endsection